package org.lanqiao.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.lanqiao.bean.EduUserBean;
import org.lanqiao.myUtils.Myutils;
import org.lanqiao.service.FactoryService;

public class UserInfoSevelet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {


		EduUserBean eub = (EduUserBean) Myutils.getNewInstance(EduUserBean.class);
		// 存id
		eub.setUserid(Myutils.getInteger(request.getParameter("userId")));
		// 存名字
		eub.setUsername(request.getParameter("userName"));
		// 存密码
		eub.setUserpassword(request.getParameter("userPassword"));
		// 存密码
		eub.setUsersex(request.getParameter("userSex"));
		// 存年龄
		eub.setUserage(Myutils.getInteger(request.getParameter("userAge")));
		// 存电话
		eub.setUsertel(request.getParameter("userTel"));
		// 存地址
		eub.setUseradress(request.getParameter("userAddress"));

		boolean result = FactoryService.getUserInfoManageService().saveResult(eub);

		if (result) {
			// 日志输出
			LogFactory.getLog("systemOut").info("登陆成功");
			// 信息插入成功之后
			// 获取真个数据库的信息
			List<EduUserBean> listUser = FactoryService.getUserInfoManageService().getUserList(eub);
			// 把信息打包给session带走
			request.getSession().setAttribute("UserScope", listUser);

			// 跳转页面
			request.getRequestDispatcher("logined/UserInfoManager/userInfoResultSuccess.jsp").forward(request,
					response);
		} else {
			request.getSession().setAttribute("pageErrorInfo", "信息添加失败");
			response.sendRedirect("logined/UserInfoManager/userInfoResultFalse.jsp");
		}

	}

	private void info(String string) {
		// TODO Auto-generated method stub

	}

}
